package java_thinking.unit_16;

import java.util.Arrays;

/**
 * @Desc:
 * @author: cww
 * @DateTime: 2019-04-09 21:46
 */
class DataHolder {
    protected int data;

    public DataHolder(int data) {
        this.data = data;
    }

}
class DataHolderWithEquals extends DataHolder {

    public DataHolderWithEquals(int data) {
        super(data);
    }
    @Override
    public boolean equals(Object c) {
        return c instanceof DataHolderWithEquals && data == ((DataHolder)c).data;
    }
}
public class E19_ArrayEquals {
    public static void main(String[] args) {
        DataHolder[] a1 = new DataHolder[4];
        DataHolder[] a2 = new DataHolder[4];
        Arrays.fill(a1,new DataHolder(1));
        Arrays.fill(a2,new DataHolder(1));
        String[] s1 = new String[4];
        Arrays.fill(s1,"HI");
        String[] s2 = {new String("HI"),new String("HI"),new String("HI"),new String("HI")};
        /**
         * 注意这里的区别，string类型的对比结果是true，Object子类都是false，因为数组最终放的都是引用地址
         */
        System.out.println(Arrays.equals(a1,a2));
        System.out.println(Arrays.equals(s1,s2));

        Arrays.fill(a1, new DataHolderWithEquals(1));
        Arrays.fill(a2, new DataHolderWithEquals(1));
        System.out.println(Arrays.equals(a1, a2));
        System.out.println("*************");
        int[][] table1 =
                {{1, 2, 3},
                        {4, 5},
                        {7, 8, 9, 10}};
        int[][] table2 =
                {{1, 2, 3},
                        {4, 5},
                        {7, 8, 9, 10}};
        Integer[][] table3 =
                {{1, 2, 3},
                        {4, 5},
                        {7, 8, 9, 10}};
        int[][] table4 =
                {{1, 2, 3},
                        {6, 5, 4},
                        {7, 8}};
        System.out.println(Arrays.deepEquals(table1, table2));
        System.out.println(Arrays.deepEquals(table1, table3));
        System.out.println(Arrays.deepEquals(table1, table4));
        Integer o = new Integer(1);
        System.out.println(((Comparable)o).compareTo(1));
    }
}
